package products.view;

import java.util.List;
import products.controller.ProductManager;
import products.model.Product;


import com.opensymphony.xwork2.ActionSupport;


public class ProductAction extends ActionSupport {

	private static final long serialVersionUID = 9149826260758390091L;
	private Product Product;
	private List<Product> ProductList;
	private Integer id;

	private ProductManager linkController;

	public ProductAction() {
		linkController = new ProductManager();
	}

	public String execute() {
		this.ProductList = linkController.list();
		return SUCCESS;
	}

	public String add() {
		System.out.println(getProduct());
		try {
			linkController.add(getProduct());
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.ProductList = linkController.list();
		return SUCCESS;
	}

	public String delete() {
		linkController.delete(getId());
		return SUCCESS;
	}

	public Product getProduct() {
		return Product;
	}

	public List<Product> getProductList() {
		return ProductList;
	}

	public void setProduct(Product Product) {
		this.Product = Product;
	}

	public void setProductList(List<Product> ProductsList) {
		this.ProductList = ProductsList;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
}
